/**
 * Todo:
 * End script on gui close
**/
package org.scripts.boot;

import org.farming.Patches;

import org.scripts.watcher.gui.*;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;

import org.powerbot.concurrent.Task;
import org.powerbot.concurrent.strategy.Condition;
import org.powerbot.concurrent.strategy.Strategy;

import org.powerbot.game.api.ActiveScript;
import org.powerbot.game.api.Manifest;
import org.powerbot.game.api.methods.Settings;
import org.powerbot.game.api.methods.Game;
import org.powerbot.game.api.util.Time;

import org.powerbot.game.api.methods.Settings;

@Manifest(name = "Farming Api Crop Watcher", description = "Gives you info on some farming patches.", version = 0.0, authors = { "DEADBEEF" })
public class Watcher extends ActiveScript implements Task, Condition {
	final WatcherFrame gui = new WatcherFrame();
	@Override
	protected void setup() 
    {
        Patches.setSettings(Settings.get());
        gui.setVisible(true);
        provide(new Strategy(this, this));
	}

    public boolean validate() {
        return true;
    }

    public boolean isValid() {
        return true;
    }
    @Override
    public void run() {
        if(!isPaused()&&Game.getClientState()==Game.INDEX_MAP_LOADED)
        {//Only update when script isn't paused and player is in game (Settings don't work in lobby)
            Patches.setSettings(Settings.get());//Settings can only be taken from an executing activescript.
            gui.update();
        }
        Time.sleep(5000);                   //Sleep for 5 seconds before we update the gui again.
    }
    @Override
    public void onStop() 
    {
        gui.dispose();
	}
}